<template>
    <div class="pad20">
        <div class="filter-container">
            <!--查询的表单数据-->
            <el-form :inline="true" :model="map" size="mini">
                <el-form-item label="店铺名称:">
                    <el-input v-model.trim="map.name"></el-input>
                </el-form-item>
                <el-form-item label="审核状态:">
                    <el-select v-model="map.state" class="auto-width" clearable filterable placeholder="状态" style="width: 85px">
                        <el-option
                                v-for="item in opts.isPutawayList"
                                :key="item.code"
                                :label="item.desc"
                                :value="item.code">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button icon='el-icon-search' type="primary" @click="handleCheck">查询</el-button>
                    <el-button icon='el-icon-refresh' class="filter-item" @click="handleReset">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <!--审核的弹框-->
        <el-dialog
                title="店铺"
                :visible.sync="checkvisible"
                :before-close="closeCllback1"
                width="30%">
            <el-form ref="checkformDataRef" :model="checkformData" label-width="100px" :rules="rules">
                <el-form-item label="审核状态：" prop="state">
                    <el-radio-group v-model="checkformData.state">
                        <el-radio label="1">通过</el-radio>
                        <el-radio label="2">不通过</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="备注：" prop="content">
                    <el-input type="textarea" :rows="3" placeholder="系统默认通过" v-model="checkformData.content"></el-input>
                </el-form-item>
            </el-form>
            <el-row style="margin-top:17px; ">
                <el-button style="float:right;margin-left:6px;" size="mini" type="danger" plain @click="resetCheck">取 消</el-button>
                <el-button style="float:right" size="mini" type="primary" @click="submitCheckForm">确定</el-button>
            </el-row>
        </el-dialog>
        <!--数据表格-->
        <el-table  size="medium" :data="list" stripe border>
            <el-table-column type="index" label="序号" width="100" align="center">
            </el-table-column>
            <el-table-column prop="shop.name" label="店铺名称" align="center">
            </el-table-column>
            <el-table-column prop="remark" label="申请理由" align="center">
            </el-table-column>
            <el-table-column prop="gmtCreate" label="申请时间" align="center">
            </el-table-column>
            <el-table-column prop="emp.nickName" label="审核人" align="center">
            </el-table-column>
            <el-table-column prop="gmtModified" label="审核时间" align="center">
            </el-table-column>
            <el-table-column
                    label="审核状态"
                    prop="shop.state"
                    width="80"
                    align="center">
                <template slot-scope="scope">
                    <el-tag type="warning" v-if="scope.row.shop.state === 0">未审核</el-tag>
                    <el-tag type="success" v-if="scope.row.shop.state === 1">已通过</el-tag>
                    <el-tag type="danger" v-if="scope.row.shop.state === 2">不通过</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                    <el-button  type="primary" @click="handleCheckBusiness(scope.row)" size="mini" v-if="scope.row.shop.state === 0">审核</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
                background
                style="float: right;margin-top: 20px; margin-bottom: 22px"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :page-size="page.pageSize"
                :page-sizes="[5, 8, 10, 15, 20, 30]"
                layout="total, sizes, prev, pager, next, jumper"
                :total="page.totalCount">
        </el-pagination>
    </div>
</template>

<script>
    export default {
        name: "shopList",
        data() {
            return {
                checkvisible:false,
                map: {},
                formData: {},
                checkformData:{},
                list: [],
                page: {
                    // beginPageIndex: 1,
                    currentPage: 1,
                    // endPageIndex: 8,
                    pageCurrent: 1,
                    pageSize: 5,
                    totalCount: 0,
                    totalPage: 0
                },
                opts: {
                    isPutawayList: [{
                        code: 0,
                        desc:"未审核"
                    },{
                        code: 1,
                        desc:"已通过"
                    },{
                        code: 2,
                        desc:"不通过"
                    }]
                },
                rules: {
                    state: [
                        { required: true, message: '请选择审核状态', trigger: 'change' }
                    ],
                    content: [
                        { required: true, message: '请填写备注', trigger: 'blur' }
                    ],
                }
            }
        },
        created() {
            this.searchCheckShop()
            this.$http.post("/shop/api/checkshop/findAll?currentPage="+this.page.pageCurrent+"&pageSize="+this.page.pageSize,this.map).then(function (resp) {
                console.log(resp);
                if (resp.data.code==2000){
                    that.list = resp.data.data.list
                    that.page.totalCount = resp.data.data.total
                    // that.page.pageSize = resp.data.data.size
                }
            })
        },
        methods: {
            // 商家分页列表接口
            searchCheckShop(){
                var that =this
                // this.map.pageCurrent = this.page.pageCurrent;
                // this.map.pageSize = this.page.pageSize;
                this.$http.post("/shop/api/checkshop/findAll?currentPage="+this.page.pageCurrent+"&pageSize="+this.page.pageSize,this.map).then(function (resp) {
                    console.log(resp);
                    if (resp.data.code==2000){
                        that.list = resp.data.data.list
                        that.page.totalCount = resp.data.data.total
                        // that.page.pageSize = resp.data.data.size
                    }
                })
            },
            //提交审核的表单
            submitCheckForm(){
                this.$refs['checkformDataRef'].validate((valid) => {
                    if (valid) {
                        var that = this
                        console.log(this.checkformData)
                        this.$http.post("/shop/api/checkshop/updateState", this.checkformData).then(function (resp) {
                            if (resp.data.code == 2000) {
                                that.$message.success(resp.data.msg);
                                that.checkvisible = false
                                that.searchCheckShop()
                            }
                        })
                    }
                })
            },
            //审核取消后清空
            resetCheck(){
                this.checkvisible = false
                this.checkformData.content = ""
                this.reload()
            },
            //查询
            handleCheck() {
                this.searchCheckShop()
            },
            // 重置查询条件
            handleReset() {
                this.reload()
            },
            handleSizeChange(val) {
                this.page.pageSize = val
                this.searchCheckShop()
            },
            handleCurrentChange(val) {
                this.page.pageCurrent = val
                this.searchCheckShop()
            },
            // 刷新当前页面
            reload() {
                this.map = {}
                this.formData = {}
                this.searchCheckShop()
            },
            //关闭审核弹框回调
            closeCllback1(){
                this.checkvisible = false;
                this.$refs.checkformDataRef.resetFields();
                this.reload()
            },
            //审核弹框
            handleCheckBusiness(row){
                this.checkformData.id = row.id;
                this.checkformData.shopid = row.shopid;
                this.checkvisible = true
            },
        }
    }
</script>

<style scoped>

</style>
